package com.hmis.domain.dto;

import com.hmis.domain.Prescription;
import com.hmis.domain.PrescriptionMedicine;
import lombok.Data;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Data
public class PrescriptionDto {
    private Prescription prescription;
    private List<PrescriptionMedicine> prescriptionMedicineList;

    public String getPrescriptionDtoString(){
        String str;
        str = "处方号：" + prescription.getPrescriptionId() +
                "\n病历号：" + prescription.getPatientId() +
                "\n病人姓名：" + prescription.getPatientName() +
                "\n主治医生：" + prescription.getDoctorName() +
                "\n开方时间：" + prescription.getCreateTime() +
                "\n总价：" + prescription.getTotalPrice() + "元" +
                "\n是否缴费：" ;
        if(prescription.getStatus()==0){
            str += "未缴费";
        }else {
            str += "已缴费";
        }
        if(prescriptionMedicineList == null || prescriptionMedicineList.size() == 0){
            return str;
        }
        str += "\n药品信息：" +
                "\n名称\t\t数量\t\t总价\t\t用量";
        //表格对齐
        for(PrescriptionMedicine prescriptionMedicine : prescriptionMedicineList){
            str += "\n" + prescriptionMedicine.getMedicine() + "\t" +
                    prescriptionMedicine.getCopies() + "\t\t" +
                    prescriptionMedicine.getTotalPrice() + "\t\t" +
                    prescriptionMedicine.getDosage();
        }
        return str;
    }

    public void addPrescriptionMedicine(PrescriptionMedicine prescriptionMedicine){
        if(prescriptionMedicineList == null){
            prescriptionMedicineList = new ArrayList<>();
        }
        prescriptionMedicineList.add(prescriptionMedicine);
        double medicinePrice = prescriptionMedicine.getTotalPrice().doubleValue();
        double totalPrice = prescription.getTotalPrice().doubleValue()+medicinePrice;
        prescription.setTotalPrice(new BigDecimal(totalPrice));
    }
}
